'''
QLabel与伙伴控制
mainLayout.addWidget(控件对象, row, column, rowSize, colSize)
'''
from PyQt5.QtGui import QFont
from PyQt5.QtWidgets import *
import sys


class QLabelBuddy(QDialog):
    def __init__(self):
        super().__init__()
        self.iniUI()

    def iniUI(self):
        self.setWindowTitle('QLabel与伙伴控制')

        namelabel = QLabel('&Name：', self)
        namelabel.setFont(QFont('微软雅黑', 20))
        nameLineEdit = QLineEdit(self)
        #  设置伙伴
        namelabel.setBuddy(nameLineEdit)

        passworldLabel = QLabel('&Password：', self)
        passworldLabel.setFont(QFont('微软雅黑', 20))
        passwordLineEdit = QLineEdit(self)
        passworldLabel.setBuddy(passwordLineEdit)

        btnOK = QPushButton('&OK')
        btnOK.setFont(QFont('微软雅黑', 10))
        btnCancel = QPushButton('&Cancel')
        btnCancel.setFont(QFont('微软雅黑', 10))

        # mainLayout = QGridLayout(self)
        mainLayout = QGridLayout()
        mainLayout.addWidget(namelabel, 0, 0, 1, 1)
        mainLayout.addWidget(nameLineEdit, 0, 1, 1, 2)

        mainLayout.addWidget(passworldLabel, 1, 0)
        mainLayout.addWidget(passwordLineEdit, 1, 1, 1, 2)

        mainLayout.addWidget(btnOK, 2, 1)
        mainLayout.addWidget(btnCancel, 2, 2)
        # self.setLayout(mainLayout)
        self.setLayout(mainLayout)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    main = QLabelBuddy()
    main.show()
    sys.exit(app.exec_())
